Vue js valueOf function: The array itself is returned by the function valueOf() method. The original array is unchanged by the function valueOf() method.In this tutorial, we will explain how to use the native javascript valueOf() function with Vue.
Get All Value of an array in Vue JS
You can use the array valueof method in Vue to find all elements from the array given simply as below:
Vue.js Array valueOf Function Example
<div id="app">
<button @click="myFun">click me</button>
<p>{{array}}</p>
<p v-html="result"></p>
</div>
<script type="module">
import { createApp } from 'vue'
createApp({
data()
{
return{
array:['India','Pakistan','America','England','Africa'],
result:''
}
},
methods:{
myFun(){
this.result = this.array.valueOf();
},
}
}).mount('#app')
</script>
Output of above example
Extracting all values from a Array of Objects in Vue Js
You can use the array valueof() method in Vue to find all values in an array of objects, in Vue js given simply as below:
Vue.js Array valueOf Function from Object Example
<div id="app">
<button @click='myFunction' class='btn btn-primary'>click me </button>
<p v-for="result in results">{{result}}</p>
</div>
<script type="module">
import { createApp } from 'vue'
createApp({
data()
{
return{
countries:[
{
'countryName':'Australia',
'capitalName':'Canberra'
},
{
'countryName':'England',
'capitalName':'London'
},
{
'countryName':'India',
'capitalName':'New Delhi'
},
],
results : ''
}
},
methods:{
myFunction(){
this.results = this.countries.valueOf()
},
}
}).mount('#app')
</script>